<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!--   <script>
        var sum = [5, 6, 7, 8, 4, 9];
        var num = '';
        for (let i = 0; i < sum.length; i++) {
            if (i == sum.length - 1) {
                num = num + sum[i];
                break;
            }
            num = num + sum[i] + '*';
        }
        console.log(num);




        //封装
        //arr数组   type符号

        function join(arr, type) {
            //创建空字符串集
            var str = '';
             //遍历数组
            for (let i = 0; i < arr.length; i++) {
                //满足条件执行if中的过程，不满足执行if外的过程
                if (i == arr.length - 1) {
                    str = str + arr[i];
                      //终止所有循环
                    break;

                }
                str += arr[i] + type;
            }
             //返回创建好的空字符串集res
            return str;
        }
        console.log(join([5, 6, 7, 8, 4, 9], "*"));
    </script> -->



    <script>
        // 用函数封装一个数组的join方法
        // 将数组转换成字符串
        arr = [21, 35, 66, 73, 35, 3]
        /* var str = ""
        for (let i = 0; i < arr.length - 1; i++) {
           str += arr[i] + ",";
            console.log(i);
        }
        str += arr[i]; */


      /*   
        function join(array, b = ",") {
         var str = ""
        for (var  i = 0; i < arr.length - 1; i++) {
           str += arr[i] + b;
          
        }
        str += arr[i]; 
        return str;
        
        }
        var num = join(arr,"*");
        console.log(num); 
 */


        Array.prototype.join2 = function (b = ",") {
            var str = ""
        for (var  i = 0; i < this.length - 1; i++) {
           str += this[i] + b;
          
        }
        str += this[i]; 
        return str;
        }
        arr.join2();
        console.log( arr.join2("*"));
    </script>
</body>

</html>